from playwright.sync_api import sync_playwright
import  time
def run(playwright):
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()

    # Open new page
    page = context.new_page()

    # Go to https://www.lessonplan.cn/home/courseware/ff2bd320-820d-11eb-8959-4d0882f40cc4
    page.goto("https://www.lessonplan.cn/home/courseware/ff2bd320-820d-11eb-8959-4d0882f40cc4")

    time.sleep(2)
    # Go to https://www.lessonplan.cn/contentStore/content
    page.goto("https://www.lessonplan.cn/contentStore/content")
    time.sleep(2)
    # Click button:has-text("登录")
    page.click("button:has-text(\"登录\")")
    # assert page.url == "https://passport.lessonplan.cn/?returnURL=www.lessonplan.cn"

    # Click [placeholder="电话 / 电子邮箱"]
    page.click("[placeholder=\"电话 / 电子邮箱\"]")

    # Fill [placeholder="电话 / 电子邮箱"]
    page.fill("[placeholder=\"电话 / 电子邮箱\"]", "sunwu")
    time.sleep(2)
    # Press Tab
    page.press("[placeholder=\"电话 / 电子邮箱\"]", "Tab")

    # Fill [placeholder="密码"]
    page.fill("[placeholder=\"密码\"]", "sunwu123")

    # Click text=登 录
    page.click("text=登 录")

    # Go to https://www.lessonplan.cn/?token=1615428557561_f2660eca-6d47-16cd-5cfe-44662f5d75d2
    page.goto("https://www.lessonplan.cn/?token=1615428557561_f2660eca-6d47-16cd-5cfe-44662f5d75d2")

    # Go to https://www.lessonplan.cn/home/myPacket/packetFile?token=1615428557561_f2660eca-6d47-16cd-5cfe-44662f5d75d2
    page.goto("https://www.lessonplan.cn/home/myPacket/packetFile?token=1615428557561_f2660eca-6d47-16cd-5cfe-44662f5d75d2")

    # Click text=上传PPT
    page.click("text=上传PPT")

    # Click ul[role="group"] >> text=ppt测试
    page.click("ul[role=\"group\"] >> text=ppt测试")

    # Click button:has-text("确定")
    page.click("button:has-text(\"确定\")")

    # Click :nth-match(input[type="radio"], 2)
    page.click(":nth-match(input[type=\"radio\"], 2)")

    # Click button:has-text("选择PPT开始上传")
    page.click("button:has-text(\"选择PPT开始上传\")")

    # Upload 1.3.pptx
    page.set_input_files("button:has-text(\"选择PPT开始上传\")", "C:/Users/acmis/Desktop/testppt/5.1.pptx")

    # Click [placeholder="请输入教案标题"]
    page.click("[placeholder=\"请输入教案标题\"]")

    # Click text=教案转换完毕 ! 标题1/40副标题0/50完成生成
    page.click("text=教案转换完毕 ! 标题1/40副标题0/50完成生成")

    # Fill [placeholder="请输入教案标题"]
    page.fill("[placeholder=\"请输入教案标题\"]", "测试教案的名称")

    # Click button:has-text("完成生成")
    page.click("button:has-text(\"完成生成\")")
    
    # ---------------------
    context.close()
    browser.close()

with sync_playwright() as playwright:
    run(playwright)